#!/usr/bin/env bash

hn=`cat /etc/hostname`
echo $hn
if [ "$hn" = "wolferhua-dell" ]; then
    ip=`ifconfig wlp2s0|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"`
elif [ "$hn" = "wolferhua-PC" ]; then
    ip=`ifconfig wlp3s0|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"`
else
    ip=`ifconfig enp0s31f6|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"`
fi
echo $ip


# 清除之前运行数据
# docker ps -a  |awk '{print $1}'|xargs docker rm
# docker images |grep "<none>"  |awk '{print $3}'|xargs docker rmi
docker ps -a|grep Exited |awk '{print $1}'|xargs docker rm >/dev/null 2>&1
# 启动php
#docker run --name nginx80 \
#-d -v /home/wolferhua/workspace/dockers/nginx/conf:/etc/nginx \
#-v /home/wolferhua/workspace/php:/home/wolferhua/workspace/php \
#-p 80:80 \
#nginx

docker ps -a|grep php56 |awk '{print $1}'|xargs docker stop >/dev/null 2>&1
docker ps -a|grep php56 |awk '{print $1}'|xargs docker rm >/dev/null 2>&1
# php 5.6
docker run -d \
--name php56 \
-d -v ~/workspace/dockers/wuhua/php56/etc:/usr/local/etc \
-v ~/workspace/php:/www \
--add-host=sapi.local.yingxiong.com:$ip \
--add-host=spro.local.yingxiong.com:$ip \
--add-host=sapi.bbsdev.yingxiong.com:$ip \
--add-host=kfapi.local.yingxiong.com:$ip \
--restart=always \
 wolferhua/php:5.6-fpm
# php 5.6
docker run -d \
--name php56li \
-d -v ~/workspace/dockers/wuhua/php56li/etc:/usr/local/etc \
-v ~/workspace/php:/www \
--add-host=sapi.local.yingxiong.com:$ip \
--add-host=spro.local.yingxiong.com:$ip \
--add-host=sapi.bbsdev.yingxiong.com:$ip \
--add-host=kfapi.local.yingxiong.com:$ip \
--restart=always \
 wolferhua/php:5.6-fpm-li

docker ps -a|grep php72 |awk '{print $1}'|xargs docker stop >/dev/null 2>&1
docker ps -a|grep php72 |awk '{print $1}'|xargs docker rm >/dev/null 2>&1
# php 7
docker run -d --name php72 \
-d \
-v ~/workspace/php:/www \
-v ~/workspace/dockers/wuhua/php72/etc:/usr/local/etc \
--add-host=webim.local.yingxiong.com:$ip \
--add-host=spro.local.yingxiong.com:$ip \
--add-host=bbs.local.yingxiong.com:$ip \
--add-host=kfapi.local.yingxiong.com:$ip \
--restart=always \
--log-driver=gelf \
--log-opt gelf-address=udp://${ip}:12201  \
--log-opt tag=php72 \
 wolferhua/php:7.2-fpm




docker ps -a|grep php71kod |awk '{print $1}'|xargs docker stop >/dev/null 2>&1
docker ps -a|grep php71kod |awk '{print $1}'|xargs docker rm >/dev/null 2>&1
docker run -d --name php71kod \
-v ~/workspace/php/KODExplorer:/kod/www \
-v ~/Desktop:/kod/wolferhua/Desktop \
-v ~/Documents:/kod/wolferhua/Documents \
-v ~/Downloads:/kod/wolferhua/Downloads \
-v ~/Pictures:/kod/wolferhua/Pictures \
-v ~/Videos:/kod/wolferhua/Videos \
-v ~/Templates:/kod/wolferhua/Templates \
-v ~/Music:/kod/wolferhua/Music \
-v ~/workspace:/kod/wolferhua/workspace \
-d -v ~/workspace/dockers/wuhua/php71root/etc:/usr/local/etc \
--add-host=webim.local.yingxiong.com:$ip \
--add-host=kfapi.local.yingxiong.com:$ip \
--restart=always \
 wolferhua/php:7.1-fpm-root




# docker run -it wolferhua/php:7.1-fpm-root


docker ps -a|grep nginx80 |awk '{print $1}'|xargs docker stop >/dev/null 2>&1
docker ps -a|grep nginx80 |awk '{print $1}'|xargs docker rm >/dev/null 2>&1
# 启动nginx
docker run --name nginx80 \
--link php56:php56 \
--link php56li:php56li \
--link php72:php72 \
--link php71kod:php71kod \
-d \
-v ~/workspace/dockers/wuhua/nginx/conf:/etc/nginx \
-v ~/workspace/php:/www \
-v ~/workspace/php/KODExplorer:/kod/www \
--log-driver=gelf \
--log-opt gelf-address=udp://${ip}:12201  \
--log-opt tag=nginx \
-p 80:80 \
--restart=always \
wolferhua/nginx:1.13.6





#docker run -d \
#--name apache56 \
#-d -v ~/workspace/dockers/wuhua/apache56/php/etc:/usr/local/etc \
#-d -v ~/workspace/dockers/wuhua/apache56/apache2:/etc/apache2  \
#-v ~/workspace/php:/www \
# wolferhua/php:5.6-apache
# hosts
#docker cp  /etc/hosts php71:/etc/hosts


# docker ps -a|grep registry |awk '{print $1}'|xargs docker stop >/dev/null 2>&1
# docker ps -a|grep registry |awk '{print $1}'|xargs docker rm >/dev/null 2>&1
# docker run -d -p 5000:5000  -v ~/workspace/registry/:/var/lib/registry/ --restart always --name registry registry:2

# docker ps -a|grep myjenkins |awk '{print $1}'|xargs docker stop >/dev/null 2>&1
# docker ps -a|grep myjenkins |awk '{print $1}'|xargs docker rm >/dev/null 2>&1
# docker run --name myjenkins -u jenkins -p 8080:8080 -p 50000:50000  -v ~/workspace/jenkins/:/var/jenkins_home reg.qiniu.com/library/jenkins


docker ps -a|grep mariadb |awk '{print $1}'|xargs docker stop >/dev/null 2>&1
docker ps -a|grep mariadb |awk '{print $1}'|xargs docker rm >/dev/null 2>&1
docker run --rm \
-p 3306:3306 \
--name mariadb  \
-v ~/workspace/mariadb/:/var/lib/mysql \
-v ~/workspace/dockers/wuhua/mysql/:/etc/mysql \
-e MYSQL_ROOT_PASSWORD=root \
-d \
reg.qiniu.com/library/mariadb
